import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

import '../screen_service.dart';

class VideoOnley extends StatefulWidget{

  String video;
  VideoOnley({ @required this.video});
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _VideoOnley();
  }
}

class _VideoOnley extends State<VideoOnley>{

  VideoPlayerController _controller;
  Future videoPlayFuture;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(widget.video);
    videoPlayFuture = _controller.initialize();
    _controller.setLooping(true);
    _controller.play();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Stack(
        children: <Widget>[
          FutureBuilder(
            future: videoPlayFuture,
            builder: (BuildContext contex, value) {
              if (value.connectionState == ConnectionState.done) {
                return Center(
                  child: Container(
                      width: ScreenService.width,
                      child: AspectRatio(
                        aspectRatio: _controller.value.aspectRatio,
                        child: VideoPlayer(_controller),
                      )),
                );
              } else {
                return Container(
                  alignment: Alignment.center,

                  ///圆形加载进度
                  child: CircularProgressIndicator(
                      valueColor: AlwaysStoppedAnimation<Color>(Colors.grey)),
                );
              }
            },
          ),
          Positioned(top: 50,left: 40,
            child: GestureDetector(
              onTap: (){
                Navigator.pop(context);
              },
              child: Image.asset('assets/image/homex.png',width: 20,height: 20,),
            ))
        ],
      ),
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}